const http = require("http");
const server = http.createServer();
const querystring = require("querystring");
server.on('request', (req, res) => {
    res.setHeader('Content-Type', "text/html;charset=utf-8");
    if (req.method == "GET") {
        let url = new URL(req.url, "http://localhost:3000/");
        res.end("账号:" + url.searchParams.get("name") + "密码:" + url.searchParams.get("password"));
    }
    if (req.method == "POST") {
        var body = "";
        req.on('data', (chunk) => {
            body += chunk;
        });
        req.on('end', () => {
            res.end("<h1>账号:" + querystring.parse(body).name +
                "密码:" + querystring.parse(body).password + "</h1>");
        });

    }

});
server.listen(3000, function() {
    console.log("服务器已启动,请访问http://localhost:3000/");
});